# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=cheapskate
pkgname=haskell-cheapskate
pkgver=0.1.1.2
pkgrel=542
pkgdesc="Experimental markdown processor."
url="https://github.com/jgm/cheapskate"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' "haskell-aeson" "haskell-blaze-html" "haskell-data-default" "haskell-http-types"
         "haskell-syb" "haskell-uniplate" "haskell-wai"
         "haskell-wai-extra" "haskell-xss-sanitize")
makedepends=('ghc')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('b671ada413b8bd90f28b008c7bada4b744dedac2c7711090f1148dfa1643f7843f44e56c9a5a99fd0f71ded8393a0095b04fbdf73f70a707698dc9fb76ed1b45')

prepare() {
    cd $_hkgname-$pkgver
    sed -e '/import Data.Aeson/a import Data.Aeson.Key' \
        -e 's/T.pack "name"/fromText(T.pack "name")/' \
        -e 's/T.pack "html"/fromText(T.pack "html")/' \
        -e 's/T.pack "version"/fromText(T.pack "version")/' \
        -i bin/cheapskate-dingus.hs
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -fdingus
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
